from common.readyaml import ReadYamlData
import random
import time


class DebugTalk:
    def __init__(self):
        self.read=ReadYamlData()

    def get_extract_order_data(self,data,randoms):
        if randoms  not in [0,-1,-2]:
            return data[randoms-1]

    def get_extract_data(self,node_name,randoms=None):
        """
        获取extract.yaml的数据
        node_name:extract.yaml中的key值
        randoms:随机读取extract.yaml中的数据(0：随机读取；-1：读取全部，返回字符串形式；-2：读取全部，返回列表形式)
        """
        data=self.read.get_extract_yaml(node_name)
        if randoms is not None:
            randoms = int(randoms)
            data_value={
                randoms:self.get_extract_order_data(data,randoms),
                0:random.choice(data),
                -1:','.join(data),
                -2:','.join(data).split(',')
            }
            data = data_value[randoms]

        return data
    
    def get_stamp_time(self):
        """获取当前时间戳，10位"""
        t = int(time.time())
        return t
    